package com.ruoyi.flowable.listener;

import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.flowable.factory.FlowServiceFactory;
import lombok.extern.slf4j.Slf4j;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;

@Slf4j
public class MultiadduserIdListener implements ExecutionListener {
    FlowServiceFactory flowServiceFactory;


    public MultiadduserIdListener() {
        flowServiceFactory = SpringUtils.getBean("flowServiceFactory");
    }


    //主子流程同步及 多实例完成条件
    @Override
    public void notify(DelegateExecution execution) {
        if (execution.getVariable("userIdflag")==null&&execution.getVariable("userIdflagref")==null){
            // flag 已完成的子流程
            // ref 已发起的子流程
            flowServiceFactory.getRuntimeService().setVariable(execution.getProcessInstanceId(), "userIdflag", 0);
            flowServiceFactory.getRuntimeService().setVariable(execution.getProcessInstanceId(), "userIdflagref", 0);
        }
    }
}
